(ns pe.p48
  (:use clojure.contrib.math))

(defn pows [] (map first (iterate 
  (fn [[val idx]]
    (let [ni (inc idx)]
      [(expt ni ni) ni])) [1 1])))

(defn last-digits [dig-cnt n]
  (rem n (expt 10 dig-cnt)))

(def last-10-digits (partial last-digits 10))

(println (last-10-digits (reduce + (map last-10-digits (take 1000 (pows))))))